package com.croqodile.whiteboard {
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.display.Sprite;
    import flash.system.Security;
    import com.senocular.utils.Output;
    import flash.utils.Timer;
    import com.croqodile.*;
    import com.croqodile.whiteboard.*;
    import flash.events.*;
    
    public class WhiteboardIsland extends IslandReplica {
	
	private var _canvas:Sprite;
	private var _segments:Array = [];
	
	public function WhiteboardIsland(){
	    super();
	}

	public static function create(canvas:Sprite):WhiteboardIsland{
	    var newIsland:WhiteboardIsland = new WhiteboardIsland();
	    newIsland._canvas = canvas;
	    return newIsland;
	}


	override public function freeze():Object{
	    var data:Object = new Object();
	    data.segments = [];
	    for(var i:int = 0; i < this._segments.length; i ++){
		var segment:Object = this._segments[i];
		data.segments.push(segment);
	    }
	    return data;
	}
	
	override public function unfreeze(data:Object):void {
	    for(var i:int = 0; i < data.segments.length; i++){
		var segment:Object = data.segments[i];
		this.drawSegment(segment);
		this._segments.push(segment);
	    }
	}

	public function drawSegment(seg:Object):void{
	    this._canvas.graphics.lineStyle(3, 0);
	    this._canvas.graphics.moveTo(seg.startX, seg.startY);
	    this._canvas.graphics.lineTo(seg.endX, seg.endY);
		
	}

	////////////////////////
        // External Interface //
        ////////////////////////

	public function addSegment(segment:Object):void{
	    this._segments.push(segment);
	    this.drawSegment(segment);
	}
	
    }
}


